package cn.yunhe.servlet;

import cn.yunhe.bean.Admin;
import cn.yunhe.biz.AdminService;
import cn.yunhe.dao.AdminMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


@WebServlet("/addAdminServlet")
public class addAdminServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String realadmin=request.getParameter("admin");
        String adminName=request.getParameter("adminName");
        String pwd=request.getParameter("pwd");
        Long telephone=Long.parseLong(request.getParameter("telephone"));
        String sex=request.getParameter("sex");
        AdminService adminService=new AdminService();
        Admin admin=new Admin(adminName,realadmin,pwd,telephone,sex);

        PrintWriter out=response.getWriter();


        int flag=adminService.insertAdmin(admin);
        if(flag>0){
            out.print("<script>alert('添加成功')</script>");
        }
        response.sendRedirect("adminPage.jsp");
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}

